home *** CD-ROM | disk | FTP | other *** search
- /*************************************************
- CWavePanel.c
-
- Part of the WavePanel class, to show how to use
- the DigitalControl class.
-
- SUPERCLASS = CPicture
-
- © 1989 Enrico Colombini. All rights reserved.
- *************************************************/
- #include "CWavePanel.h"
- #include <stdio.h>
-
- /*rsrc ID for DigitalControl object:*/
- #define digitalControlResID 600
-
- /*command numbers for display update*/
- #define DISPLAY_AMPA_CMD 2000L
- #define DISPLAY_FREQA_CMD 2001L
- #define DISPLAY_AMPB_CMD 2002L
- #define DISPLAY_FREQB_CMD 2003L
- #define DISPLAY_PHASEB_CMD 2004L
-
- /*DigitalControls positions*/
- #define CTR_HPOS 38
- #define CTR_AMPA_VPOS 31
- #define CTR_FREQA_VPOS 56
- #define CTR_AMPB_VPOS 154
- #define CTR_FREQB_VPOS 179
- #define CTR_PHASEB_VPOS 204
-
- /*frequency limits and display steps*/
- #define MIN_FREQ 50
- #define MAX_FREQ 1800
- #define FREQ_STEP 40
- #define FREQ_THRESHOLD 40
-
- /*non-zero starting values*/
- #define START_AMPA 100
- #define START_FREQA 600
- #define START_FREQB 600
-
- /*************************************************
- IWavePanel
-
- Initialize a CWavePanel object. The intialization
- is typical of an object descending from the
- CPicture class. However, there is no rType
- parameter, and 'PctP' is used instead.
- *************************************************/
- void CWavePanel::IWavePanel(
- short resID,
- CView *anEnclosure,
- CBureaucrat *aSupervisor)
- {
- /*first, init itself*/
- inherited::IViewRes(
- 'PctP',resID,anEnclosure,aSupervisor);
-
- /*create a DigitalControl for Amplitude A*/
- ctrAmpA = new(CDigitalControl);
- ctrAmpA->IDigitalControl(
- digitalControlResID,this,this);
- ctrAmpA->Place(CTR_HPOS,CTR_AMPA_VPOS,FALSE);
- ctrAmpA->SetDisplayCmd(DISPLAY_AMPA_CMD);
- ctrAmpA->SetValue(START_AMPA);
-
- /*create a DigitalControl for Frequency A*/
- ctrFreqA = new(CDigitalControl);
- ctrFreqA->IDigitalControl(
- digitalControlResID,this,this);
- ctrFreqA->Place(CTR_HPOS,CTR_FREQA_VPOS,FALSE);
- ctrFreqA->SetDisplayCmd(DISPLAY_FREQA_CMD);
- ctrFreqA->SetMinValue(MIN_FREQ);
- ctrFreqA->SetMaxValue(MAX_FREQ);
- ctrFreqA->SetSteps(1,FREQ_STEP,FREQ_THRESHOLD);
- ctrFreqA->SetValue(START_FREQA);
-
- /*create a DigitalControl for Amplitude B*/
- ctrAmpB = new(CDigitalControl);
- ctrAmpB->IDigitalControl(
- digitalControlResID,this,this);
- ctrAmpB->Place(CTR_HPOS,CTR_AMPB_VPOS,FALSE);
- ctrAmpB->SetDisplayCmd(DISPLAY_AMPB_CMD);
-
- /*create a DigitalControl for Frequency B*/
- ctrFreqB = new(CDigitalControl);
- ctrFreqB->IDigitalControl(
- digitalControlResID,this,this);
- ctrFreqB->Place(CTR_HPOS,CTR_FREQB_VPOS,FALSE);
- ctrFreqB->SetDisplayCmd(DISPLAY_FREQB_CMD);
- ctrFreqB->SetMinValue(MIN_FREQ);
- ctrFreqB->SetMaxValue(MAX_FREQ);
- ctrFreqB->SetSteps(1,FREQ_STEP,FREQ_THRESHOLD);
- ctrFreqB->SetValue(START_FREQB);
-
- /*create a DigitalControl for relative Phase*/
- ctrPhaseB = new(CDigitalControl);
- ctrPhaseB->IDigitalControl(
- digitalControlResID,this,this);
- ctrPhaseB->Place(
- CTR_HPOS,CTR_PHASEB_VPOS,FALSE);
- ctrPhaseB->SetDisplayCmd(DISPLAY_PHASEB_CMD);
- ctrPhaseB->SetMinValue(-180);
- ctrPhaseB->SetMaxValue(180);
- }
-
- /*************************************************
- DoCommand {OVERRIDE}
-
- Handle commands from enclosed DigitalControls
- (display update), or pass command to supervisor
- if not recognized.
- *************************************************/
- void CWavePanel::DoCommand(long theCommand)
- {
- enum type { AMPL, FREQ, PHASE };
- CDigitalControl *dctrl = NULL;
- short dispType;
- short val;
- char buf[6];
-
- switch(theCommand) {
-
- case DISPLAY_AMPA_CMD:
- dctrl = ctrAmpA;
- dispType = AMPL;
- break;
- case DISPLAY_FREQA_CMD:
- dctrl = ctrFreqA;
- dispType = FREQ;
- break;
- case DISPLAY_AMPB_CMD:
- dctrl = ctrAmpB;
- dispType = AMPL;
- break;
- case DISPLAY_FREQB_CMD:
- dctrl = ctrFreqB;
- dispType = FREQ;
- break;
- case DISPLAY_PHASEB_CMD:
- dctrl = ctrPhaseB;
- dispType = PHASE;
- break;
-
- default:
- inherited::DoCommand(theCommand); /*not mine*/
- break;
- }
-
- if (dctrl != NULL) { /*display to refresh*/
- val = dctrl->GetValue();
- sprintf(buf,"%04d",val); /*build text*/
- if (dispType == AMPL) { /*AMPL: fake point*/
- buf[0] = buf[1];
- buf[1] = '.';
- } else if (dispType == PHASE) { /*add sign*/
- buf[0] = (val > 0) ? '+' :
- ((val < 0) ? '-' : ' ');
- }
- dctrl->SetDisplayText(buf); /*set new text*/
- }
- }
-
-
-